package control;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import model.BoardModel;

public class PlayerMinMax extends PlayerAI {

	private static Pos codeToPos(int pos) {
		int x = pos / 10 - 1;
		int y = pos % 10 - 1;
		return new Pos(x, y);
	}

	public static int posToCode(Pos pos) {
		return (pos.getX() + 1) * 10 + pos.getY() + 1;
	}

	public static void printBoard(int[] board) {
		if (!Minimax.debug)
			return;
		for (int i = 0; i < board.length; i++) {
			if (i % 10 == 0)
				System.out.println();
			System.out.print(board[i] + "\t");
		}
		System.out.println();
	}

	private static void printCoords() {
		for (int i = 0; i < 100; i++) {
			if (i % 10 == 0)
				System.out.println();
			System.out.print(i + "\t");
		}
		System.out.println();
	}

	public PlayerMinMax(String n, Color c, BoardModel model) {
		super(n, c, model);
	}

	@Override
	public Pos getNextMove() {		
		
		System.out.println("Color Pattern");
		Kamisado.printColorPattern();
		
		int[] board = getModel().getBoard();

		System.out.println("getNextMove board");		
		printBoard(board);

		int depth = 15;
		int move = Minimax.minimax(board,depth);

		System.out.println("getNextMove move = " + move);

		Pos pos = codeToPos(move);

		System.out.println("getNextMove pos " + pos);

		return pos;
	}
}
